package com.thornbird.vehiclerecycling.util;

import com.thornbird.vehiclerecycling.model.response.Result;
import org.springframework.http.HttpStatus;

public class ResultUtil {

    public static Result<Object> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatus.OK.value());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(Integer code, String msg) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

    public static <T> Result<T> unauthorizedError() {
        HttpStatus status = HttpStatus.UNAUTHORIZED;
        return ResultUtil.error(status.value(), status.getReasonPhrase());
    }

    public static <T> Result<T> forbiddenError() {
        HttpStatus status = HttpStatus.FORBIDDEN;
        return ResultUtil.error(status.value(), status.getReasonPhrase());
    }

    public static <T> Result<T> badRequestError() {
        HttpStatus status = HttpStatus.BAD_REQUEST;
        return ResultUtil.error(status.value(), status.getReasonPhrase());
    }

    public static <T> Result<T> notFoundError() {
        HttpStatus status = HttpStatus.NOT_FOUND;
        return ResultUtil.error(status.value(), status.getReasonPhrase());
    }

    public static <T> Result<T> internalServerError() {
        HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
        return ResultUtil.error(status.value(), status.getReasonPhrase());
    }

}
